package com.neouton.crm.pm.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neouton.common.util.PageUtil;
import com.neouton.common.util.ResponseAPI;
import com.neouton.crm.customer.entity.CustomerVO;
import com.neouton.crm.pm.entity.*;
import com.neouton.crm.sales.entity.SalesFileRelationVO;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 开票记录 
 * 回款记录
 * 接口
 */
public interface BrAndBmrService {

    /**
     * 保存开票记录
     * @param billingRecordVo
     */
    Integer saveBillingRecord(BillingRecordVo billingRecordVo, String token);

    /**
     * 获取该项目中所有开票记录 / 开票申请
     * @param id
     * @param billState
     * @return
     */
    List<ContractInfoVO> getProjectAllBillingRecord(Integer id,Integer billState);

    Integer saveBackMoneyRecord(BackMoneyRecordVo backMoneyRecordVo,String token);

    /**
     * 获取该项目中所有开票记录
     * @param id
     * @return
     */
    List<ContractInfoVO> getProjectAllBackMoneyRecord(Integer id);

    /**
     * 开票页面金额显示
     * @param projectManageId
     * @param contractId
     * @param period
     * @return
     */
    ShowMoneyVo getShowMoney(Integer projectManageId, Integer contractId, List<Integer> period);

    /**
     * 回款记录页面金额显示
     * @param projectManageId
     * @param contractId
     * @param period
     * @return
     */
    ShowMoneyVo getBmrShowMoney(Integer projectManageId, Integer contractId, List<Integer> period);

    /**
     * 获取附件
     * @param salesRelationId
     * @param fileClass
     * @return
     */
    List<SalesFileRelationVO> getSalesByBillingRecordId(Integer salesRelationId, Integer fileClass);

    /**
     * 定时发布提醒邮件
     */
    void timingPushHintEmail();

    /**
     * 保存开票申请
     * @param billingApplyVo
     * @return
     */
    Integer saveBillingApply(BillingApplyVo billingApplyVo, String token);

    /**
     * 获取该项目中的开票记录(state表示通过或者不通过)
     */
    List<BillingRecordVo> getAllBillingApplyPeridName(Integer id,Integer billState, Integer state);


    BillingApplyVo searchBillingApplyByApprovalId(Integer approvalId);

    /**
     * 通过开票申请
     * @param billingApplyVo
     * @param token
     * @return
     */
    Boolean passbillingApply(BillingApplyVo billingApplyVo, String token,Boolean auto);

    /**
     * 驳回开票申请
     * @param billingApplyVo
     * @param token
     * @return
     */
    Boolean rejectBillingApply(BillingApplyVo billingApplyVo, String token);

    BillingRecordVo searchBillingRecordByApprovalId(Integer approvalId);

    Boolean passBillingRecord(BillingRecordVo billingRecordVo, String token,Boolean auto);

    Boolean rejectBillingRecord(BillingRecordVo billingRecordVo, String token);

    /**
     * 根据approvalId 查询 回款记录页面
     * @param approvalId
     * @return
     */
    BackMoneyRecordVo searchBackMoneyRecordByApprovalId(Integer approvalId);

    Boolean passBackMoneyRecord(BackMoneyRecordVo backMoneyRecordVo, String token,Boolean auto);

    Boolean rejectBackMoneyRecord(BackMoneyRecordVo backMoneyRecordVo, String token);

    /**
     * 查询合同是否通过
     * @param contractId
     * @return
     */
    ContractInfoVO ContractApplyPassOrNOByContractId(Integer contractId);

    /**
     *判断期次是否重复 -- 创建
     * @param contractId
     * @param period
     * @return
     */
    Boolean judgePeriod(Integer contractId,
                        Integer state,
                        List<Integer> period);

    Boolean judgePeriodEdit(Integer contractId,
                            Integer billingRecordId,
                            Integer state,
                            List<Integer> period);

    /**
     * 判断回款记录 期次是否重复 -- 修改/创建
     * @param contractId
     * @param bmrId
     * @param period
     * @return
     */
    Boolean judgeBmrPeriod(Integer contractId, Integer bmrId, List<Integer> period);


    PageUtil<BackMoneyRecordVo> getBmrListByPage(IPage<BackMoneyRecordVo> page, BackMoneyRecordVo backMoneyRecordVo, String orderBy, String token);

    void exportBmr(HttpServletResponse response, BackMoneyRecordVo backMoneyRecordVo, String token) throws Exception;

    PageUtil<BillingApplyVo> getBarListByPage(IPage<BillingApplyVo> page, BillingApplyVo billingApplyVo, String orderBy, String token);

    void exportBar(HttpServletResponse response, BillingApplyVo billingApplyVo, String token) throws Exception;

    PageUtil<BillingRecordVo> getBriListByPage(IPage<BillingRecordVo> page, BillingRecordVo billingRecordVo, String orderBy, String token);

    void exportBri(HttpServletResponse response, BillingRecordVo billingRecordVo, String token) throws Exception;

    /**
     * 撤回时根据审批ID修改回款计划申请金额
     * @param approvalId
     */
    void updateBackMoneyBillMoneyByApprovalId(Integer approvalId);

    void updateBilling(Integer approvalId);

    /**
     * 获取剩余金额（根据计划id）
     * @param bmpId
     * @return
     */
    BackBillingMoneyVo getResidualMoneybyBmpId(Integer bmpId);

    /**
     * 根据开票申请id查询开票申请详情
     * @param billingRecordId
     * @return
     */
    BillingApplyDto getBillingApply(Integer billingRecordId);

    /**
     * 保存关系表
     * @param backBillingMoneylist
     */
    void saveBackBillingMoney(List<BackBillingMoneyVo> backBillingMoneylist);

    List<BackBillingMoneyVo> getBackBillingMoneyByApprovalId(Integer approvalId);

    BackMoneyRecordVo getBackMoneyRecord(Integer bmrId);

    ShowMoneyVo getPlanShowMoney(Integer bmpId);

    BillingRecordVo getBillingApplyisNoChoose(Integer billingRecordId);

    BillingRecordVo getBillingRecordisNoChoose(Integer billingRecordId);

    Map<String,String> getAllPageShowMoneybyBmpId(Integer bmpId);

    List<ContractInfoVO> getProjectAllBackMoneyRecordByCustomerId(Integer customerId);

    void deleteBillingById(Integer id);

    void deleteBackMoneyRecordById(Integer id);

    void updateBackMoneyRecordAfterPass(BackMoneyRecordVo backMoneyRecordVo, String token);

    BackMoneyRecordVo querybackMoneyRecordFromCache(int bmrId, String token);

    void updateBillingRecordAfterPass(BillingRecordVo billingRecordVo, String token);

    BillingApplyVo queryBillingApplyFromCache(int billingRecordId, String token);

    void updateBillingApplyAfterPass(BillingApplyVo billingApplyVo, String token);

    BillingRecordVo queryBillingRecordFromCache(int billingRecordId, String token);

    void updateBillApplyRecordType(BillingRecordVo billingRecordVo);

    void updateBillingDetailTableAfterPass(List<BackBillingMoneyVo> backBillingMoneyVos, String token);

    List<BackBillingMoneyVo> queryBillingDetailTableFromCache(int billingRecordId, String token);

    void updateBackMoneyDetailTableAfterPass(List<BackBillingMoneyVo> backBillingMoneyVos, String token);

    List<BackBillingMoneyVo> queryBackMoneyDetailTableFromCache(int bmrId, String token);
}

